package dinner.web;

import java.util.Calendar;
import java.util.List;

import dinner.web.eat.EatDB;
import dinner.web.eat.ReportIO;
import dinner.web.secure.AutorisingSystem;
import dinner.web.secure.UnAutorizationException;

public class DinnerDAO {

	static public java.util.List<Eat> getList(long id) throws UnAutorizationException {
		return EatDB.getEatArchiveForUser(AutorisingSystem.isLogined(id), Calendar.getInstance());
	}

	static public Long login(String login, String pass) throws UnAutorizationException {
		return AutorisingSystem.login(login, pass);
	}

	static public void setList(List<Eat> list, long id) throws UnAutorizationException {
		if (ReportIO.userNotClosed(AutorisingSystem.isLogined(id))) {
			EatDB.setEatArchiveForUser(AutorisingSystem.isLogined(id), list, Calendar.getInstance());
		} else
			throw new UnAutorizationException("You can't save the data - database is already closed");
	}

	public static void clearAllLists() {
		EatDB.clearData();

	}

	public static void clearList(String logined) throws UnAutorizationException {
		if (ReportIO.userNotClosed(logined)) {
			EatDB.clearData(logined);
		} else
			throw new UnAutorizationException("You can't save the data - database is already closed");

	}

}
